//
//  SettingCell.m
//  ACSProduct
//
//  Created by preet dhillon on 28/07/12.
//  Copyright (c) 2012 dhillon. All rights reserved.
//

#import "SettingCell.h"

@implementation SettingCell
@synthesize btnCell,txtFldCell,swtchCell,delegateCell,btnSetting;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}


-(void)setViews
{
    self.txtFldCell.delegate = self;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
 
    NSLog(@"°°°°°°°°%d",[textField  tag]);
    if(textField.tag == 0)
    {
        self.swtchCell.on = NO;
        [delegateCell  showPicker];
        [self.txtFldCell  resignFirstResponder];
    }
    else
    {
        [delegateCell  settextfieldFrame:textField];
        self.swtchCell.on = NO;
        
        [textField becomeFirstResponder];
    }
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [delegateCell  downkeyPadWithvalue:[textField  text] withTag:[textField tag]];
}
-(IBAction)backKeyPad:(id)sender
{
    [sender  resignFirstResponder];
    [delegateCell  downkeyPadWithvalue:[sender  text] withTag:[sender tag]];
}

-(void)removeTheContent:(NSInteger)tag
{
    [delegateCell removeTheContent:tag];
}

//- (BOOL)textFieldShouldReturn:(UITextField *)textField
//{
// 
//}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(IBAction)clickToBtnCell:(id)sender
{
    [delegateCell clickToBtn:sender];
}


-(IBAction)clickToSwitchCell:(id)sender
{
    NSLog(@"%s %@",__PRETTY_FUNCTION__,self.btnSetting.titleLabel.text);
    
    if(self.swtchCell.on == YES)
    {
        if([self.btnSetting.titleLabel.text length]>0)
        {
//            if([sender tag]<3)
            [delegateCell clickToSwitchWithTag:[sender  tag]
                            withString:self.txtFldCell.text];
        }
        else
        {
           UIAlertView *alert = [[UIAlertView  alloc] initWithTitle:@"Please Enter Text"
                                                            message:nil
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles: nil];
            [alert  show];
            self.swtchCell.on = NO;
        }
    }
    else
    {
//        [self.txtFldCell setText:@""];
//        if([sender tag]<3)
        [delegateCell  removeTheContent:[sender  tag]];
    }
}
//-(IBAction)clickToBtnCell:(id)sender
//{
//    
//}

@end
